package com.demo.controller;

import com.demo.dto.UserDetailDto;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(value = "/user")
public class UserController {

    @GetMapping(value = "/login")
    public String login() {
        return "login";
    }

    @PostMapping(value = "/login")
    public String subLogin() {
        System.out.println("========自定义登录认证===============");
        return "success";
    }

    @GetMapping(value = "/success")
    public String success() {
        return "success";
    }

    @GetMapping(value = "/fail")
    public String fail() {
        return "fail";
    }

    @GetMapping(value = "/index")
    public String user() {
        System.out.println("===========打印账户中心======================");
        /**
         * 此处打印，只能针对session未关闭的情况下正常，否则关闭session打印时，会报错;
         */
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

        /*UserDetailDto userDetail=(UserDetailDto) authentication.getPrincipal();
        System.out.println(userDetail);*/

        return "user";
    }

}
